<!DOCTYPE html>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<meta name="viewport" content="width=device-width, initial-scale=1.0, minimum-scale=1.0, maximum-scale=1.0, user-scalable=no" />
<meta name="format-detection" content="telephone=no,email=no,adress=no"/>
<title>先花花</title>
<link rel="stylesheet" type="text/css" href="css/setting.css" />
<link rel="stylesheet" type="text/css" href="css/bootstrap.min.css" />
<link rel="stylesheet" type="text/css" href="css/sweet-alert.css" />
<script type="text/javascript" src="script/jquery.js"></script>
<script type="text/javascript" src="script/common.js"></script>
<script type="text/javascript" src="script/jquery.md5.js"></script>
<script type="text/javascript" src="script/jquery.cookie.js"></script>
<script src="script/setting.js"></script>
<script type="text/javascript">
  $(function(){
    $("#btn").click(function(){
      var oold = $("#old").val();
      if(oold==''){
        alert('原密码不能为空');
        return false;
      }
      old = $.md5(oold);
      if(verifyPassword()&&oold!=''){
        get_oldpwd();
      }
    });
  });
  //获取原来的密码
  function get_oldpwd(){
   $.ajax({
        url:commonUrl+"/Userinfo/index",
        data:{appid:appid,appkey:appkey,uid:uid},
        type:"get",
        dataType:"jsonp",
        jsonp:"callback",
        success:function(result){
          if(result.data.password == old){
            updatePasswd();
          }else{
             window.location.href="updatepwderror.html";
          }
        }
    });
  }
  //更新密码
  function updatePasswd(){
    var newPassword = $("#newPassword").val();
      $.ajax({
          url:commonUrl+"/Userinfo/updatePwd",
          data:{appid:appid,appkey:appkey,newPassword:newPassword,uid:uid},
          type:"get",
          dataType:"jsonp",
          jsonp:"callback",
          success:function(result){
            if(result.status==200){
              window.location.href="updatepwdsuccess.html";
            }else{
              window.location.href="updatepwderror.html";
            }
          }
      });
  }
  //验证密码的规则及两次密码
  function verifyPassword() {  
    var reg = /^[A-Za-z0-9]{6,20}$/;
    //验证密码格式
    var newPassword = $("#newPassword").val();
    if (!reg.test(newPassword)) {  
        $("#mobileNumberErrorDiv").empty();
        $("#mobileNumberErrorDiv").append("密码为6-20位数字字母");
        return false;
    }else{
      $("#mobileNumberErrorDiv").empty();
    }
    //验证两次密码
    var okPassword = $("#okPassword").val();
    if(newPassword != okPassword){
        $("#mobileNumberErrorDiv").empty();
        $("#mobileNumberErrorDiv").append("两次密码不同");
        return false;
    }else{
        $("#mobileNumberErrorDiv").empty();
        return true;
    }
  }  
</script>
</head>
<body>
<!-- 页面头部 -->
<section>
<div class="navigation-bar"> <a href="javascript:history.back(-1)" class="z-01"></a> <span>修改登录密码</span> <a href="index.html" class="z-02"></a> </div>
</section>
<!-- 中间内容 -->
<div class="m-wrapper">
  <div class="wrapper   ">
    <div class="login-password">
      <div class="container-fluid">
        <form class="set-password" id="set-password" onSubmit="return false;">
          <div class="form-group item">
            <input type="password" id="old" class="form-control input-lg login-input" id="old-password" name="password" tabindex="1" placeholder="请输入原登录密码">
          </div>
          <div class="item form-group">
            <input type="password" class="form-control input-lg" id="newPassword" name="password" tabindex="2" placeholder="请输入新登录密码"><label id="mobileNumberErrorDiv"></label>
          </div>
          <div class="form-group item">
            <input type="password" class="form-control input-lg" id="okPassword" name="password" tabindex="3" placeholder="请输入新登录密码">
          </div>
          <div class="form-group">
            <button type="button" class="waves-button form-control login-button input-lg waves-effect waves-effect" tabindex="4" data-dismiss="modal" id="btn">确定</button>
            <!-- Modal -->
          </div>
        </form>
        <div>
          <p class="text-center ui-fs-12 text-nowrap">若您无法通过该方式找回密码，请联系客服电话</p>
          <p class="text-center ui-fs-12 text-nowrap"><span>400-090-1268</span></p>
        </div>
      </div>
    </div>
  </div>
</div>
<!-- 页面底部 -->
<nav class="footer border_t" id="footer"> 
  <a href="index.html" class="" id="jx"><span></span>首页</a>
   <a href="list.html" id="lc" class=""><span></span>理财</a> 
  <a href="borrow_money.html" id="jk" class=""><span></span>借款</a>
   <a href="user.html" id="cf" class="nav_on"><span></span>我的账户</a> </nav>
</body>
</html>
